package com.hdoit.kylin.logical.studentManager.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.enums.OrderEnum;
import com.tennetcn.common.message.DaoBaseException;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.message.SearchModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
import com.hdoit.kylin.logical.studentManager.dao.IFinalSpeechDao;
import com.hdoit.kylin.logical.studentManager.model.FinalSpeech;

/**
 * @author liuli
 * @email
 * @createtime 2017年07月31日 10:20:09
 * @comment
 */
@Component
public class FinalSpeechDaoImpl extends SuperDao<FinalSpeech> implements IFinalSpeechDao {
	@Override
	public int queryCountByTeacherIds(SearchModel search, String teacherIds) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.addBody("select count(1) from student_final_speech,linker_teacher,linker_student ")
						.resolveSearchModel(search)
						.andWhere("student_final_speech.checkId=linker_teacher.employeeId AND student_final_speech.checkedId=linker_student.employeeId")
						.andWhere("checkId in "+teacherIds);
		return queryCount(finderExpression);
	}
	
	@Override
	public int queryCount(SearchModel search) throws DaoBaseException {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.addBody("select count(1) from student_final_speech,linker_teacher,linker_student ")
						.resolveSearchModel(search)
						.andWhere("student_final_speech.checkId=linker_teacher.employeeId AND student_final_speech.checkedId=linker_student.employeeId");
		return queryCount(finderExpression);
	}

	@Override
	public List<FinalSpeech> queryListByTeacherIds(SearchModel search,PagerModel pagerModel, String teacherIds) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.addBody("select id,checkId,checkedId,speechStatus,checkDate,checkPlace,speechVersion,student_final_speech.comments,teacherName AS checkName,studentName AS checkedName from student_final_speech,linker_teacher,linker_student ")
						.andWhere("student_final_speech.checkId=linker_teacher.employeeId AND student_final_speech.checkedId=linker_student.employeeId")
						.andWhere("checkId in "+teacherIds)
						.addOrder("checkDate", OrderEnum.desc);
		return queryList(finderExpression, search, pagerModel);
	}
	
	@Override
	public List<FinalSpeech> queryList(SearchModel search, PagerModel pagerModel) throws DaoBaseException {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.addBody("select id,checkId,checkedId,speechStatus,checkDate,checkPlace,speechVersion,student_final_speech.comments,teacherName AS checkName,studentName AS checkedName from student_final_speech,linker_teacher,linker_student ")
						.resolveSearchModel(search)
						.andWhere("student_final_speech.checkId=linker_teacher.employeeId AND student_final_speech.checkedId=linker_student.employeeId")
						.addOrder("checkDate", OrderEnum.desc);
		return queryList(finderExpression,pagerModel);
	}
	
	@Override
	public FinalSpeech queryModel(String key) throws DaoBaseException {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.addBody("select id,checkId,checkedId,speechStatus,checkDate,checkPlace,speechVersion,student_final_speech.comments,teacherName AS checkName,studentName AS checkedName from student_final_speech,linker_teacher,linker_student ")
						.andWhere("student_final_speech.checkId=linker_teacher.employeeId AND student_final_speech.checkedId=linker_student.employeeId")
						.andWhere("id = #{key}")
						.setParam("key", key);
		return queryModel(finderExpression);
	}
}